package com.zq.assistant.ui.main;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;

import com.zq.assistant.R;
import com.zq.assistant.ui.BaseActivity;
import com.zq.assistant.ui.widget.recyclerview.RecyclerViewHolder;
import com.zq.assistant.ui.widget.recyclerview.adapter.cell.BaseDataBinder;
import com.zq.assistant.ui.widget.recyclerview.adapter.cell.Cell;
import com.zq.assistant.ui.widget.recyclerview.adapter.cell.CellAdapter;
import com.zq.assistant.ui.widget.recyclerview.adapter.cell.DataBinder;
import com.zq.assistant.ui.widget.recyclerview.adapter.cell.MultiCell;
import com.zq.assistant.ui.widget.recyclerview.adapter.cell.BaseCell;
import com.zq.assistant.ui.widget.recyclerview.multi.MultiRecyclerView;
import com.zq.assistant.ui.widget.viewholder.SuperViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class CellAdapterTestActivity extends BaseActivity {

    @InjectView(R.id.multi_recycler_view)
    MultiRecyclerView multiRecyclerView;

    public static void start(Context context) {

        Intent intent = new Intent(context, CellAdapterTestActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cell_adapter_test);
        ButterKnife.inject(this);

        multiRecyclerView.setLayoutManager(new GridLayoutManager(this,2));

        CellAdapter<BaseCell> cellAdapter = new CellAdapter<>(null,this);
        multiRecyclerView.setAdapter(cellAdapter);

        List<BaseCell> baseCellList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {

            baseCellList.add(new BaseCell<String>(R.layout.item_file_info,i%3 < 2 ? 1 : 2,"index:" + i) {
                @Override
                public void bindData(RecyclerViewHolder viewHolder) {
                    viewHolder.setText(R.id.tv_name,getData());
                }
            });
        }

        cellAdapter.setDataList(baseCellList);

        cellAdapter.addDataAtLast(new MultiCell<>(R.layout.item_download_info, Cell.FULL_SPAN,1, new BaseDataBinder<Integer>() {

            @Override
            public void bindData(RecyclerViewHolder viewHolder, Integer data) {
                viewHolder.setProgress(R.id.progressBar,data);
            }
        }));
    }
}
